<?php
session_start();
require('class/auth.php');
include_once('class/autoload.php'); // pour inclure nos classes

if(Auth::islog()){
}else{
	header('Location:index.php');
}
$site = new page_securiser('acceuil');


$site->titre = "Appartement";
$site->corps='<span id="bouton_retour"><input type="button" value="Retour aux annonce" onclick="location.href=\'acceuil.php\';"></span>';

$id=$_GET['id_appart'];
$Appartement = new page_appartement($id);


$site->affiche();

if(!empty($_POST) )
{
			$Titre_annonce = addslashes($_POST['Titre_annonce']);
			$Adresse = addslashes($_POST['Adresse']);
			$Code_Postal = addslashes($_POST['Code_Postal']);
			$Ville =  addslashes($_POST['Ville']);
			$Surface =  addslashes($_POST['Surface']);
			$Distance_de_Chevrollier =  addslashes($_POST['Distance_de_Chevrollier']);
			$Prix_loyer =  addslashes($_POST['Prix_loyer']);
			$Type =  addslashes($_POST['Type']);
			$Description =  addslashes($_POST['Description']);
			
			
			$u = array('Titre_annonce'=>$Titre_annonce,'Adresse'=>$Adresse,'Code_Postal'=>$Code_Postal, 'Ville'=>$Ville, 'Surface'=>$Surface, 'Distance_de_Chevrollier'=>$Distance_de_Chevrollier, 'Prix_loyer'=>$Prix_loyer, 'Type'=>$Type, 'Description'=>$Description);
			$sql = 'UPDATE appartement SET libelleAppart = :Titre_annonce, adRue = :Adresse, adCP = :Code_Postal, adVille = :Ville,  surface = :Surface,  distanceLycee = :Distance_de_Chevrollier,  prixLoyer = :Prix_loyer,  id_avatar = :Type,  description = :Description WHERE mail = :email';
			$req = $connexion->prepare($sql);
			$req->execute($u);

			$_SESSION['id_avatar'] = $id_avatar;

			//var_dump(pathinfo($_FILES["file"]["name"]));

			//echo $_FILES["file"]["name"].'<br>';
			//var_dump($temp);
			//header('Location:coordonneeseleve.php?mail='.$mail.'');

			//echo "Stored in: " .  "images/avatar_eleve/" . $_FILES["file"]["name"];
			//}
		
	



}
?>
<script language="javascript">
function ChangeImage(url)
{
document.getElementById('img').src = url;
}


	
	</script> 
<form method="post" action="modifappartementeleve.php?id_appart=<?php echo $row['idAppart'];?>" enctype="multipart/form-data">
<div class= 'text_et_image_appart'>
<div class='texte_appart'>
<ul><span class="puce"><li><label for="Titre_annonce">Titre annonce : </label><span id="Titre_annonce_modif_appart"><input type="text" name="Titre_annonce" size="28" maxlength="50" value="<?php echo $Appartement->libelleAppart ?>"/></span></li></span>
<span class="puce"><li><label for="Adresse">Adresse : </label> <span id="Adresse_modif_appart"><input type="text" name="Adresse" size="28" maxlength="50" value=" <?php echo $Appartement->adRue ?>"/></li></span>
<span class="puce"><li><label for="Code_Postal">Code Postal : </label> <span id="Code_Postal_modif_appart"><input type="text" name="Code_Postal" size="28" maxlength="50" value=" <?php echo $Appartement->adCP ?>"/></span></li></span>
<span class="puce"><li><label for="Ville">Ville : </label> <span id="Ville_modif_appart"><input type="text" name="Ville" size="28" maxlength="50" value=" <?php echo $Appartement->adVille ?>"/></span></li></span>
<span class="puce"><li><label for="Surface">Surface : </label> <span id="Surface_modif_appart"><input type="text" name="Surface" size="28" maxlength="50" value=" <?php echo $Appartement->surface ?>"/> M&egravetre&sup2</span></li></span>
<span class="puce"><li><label for="Distance_de_Chevrollier">Distance de Chevrollier: </label> <span id="Distance_de_Chevrollier_modif_appart"><input type="text" name="Distance_de_Chevrollier" size="28" maxlength="50" value=" <?php echo $Appartement->distanceLycee/1000 ?>"/> KM&egravetre</span></li></span>
<span class="puce"><li><label for="Prix_loyer">Prix loyer: </label> <span id="Prix_loyer_modif_appart"><input type="text" name="Prix_loyer" size="28" maxlength="50" value=" <?php echo $Appartement->prixLoyer ?>"/> &euro;</span></li></span>
<span class="puce"><li><label for="Type">Type : </label> <span id="Type_modif_appart"><input type="text" name="Type" size="28" maxlength="50" value=" <?php echo $Appartement->typeA ?>"/></span></li></span>
<span class="puce"><li><label for="Description">Description : </label> <br><textarea name="Description" rows="10" cols="42"><?php echo $Appartement->description ?></textarea></li></span></ul>

<span class="submit_pad"><input type="submit" value="Valider les modifications"/></span>
</div>

</form>
<div class='image_appart'>

<img  id='img' class='imageprincipal' src=<?php $_SERVER['HTTP_ORIGIN'] ?>/images/<?php echo $Appartement->url1 ?>.jpg  alt=''/>


<table id="position_tableau">
<tr>
<td><?php if (!empty($Appartement->url1)){?><img onClick="ChangeImage(this.src);" id='image1' src=<?php $_SERVER['HTTP_ORIGIN'] ?>/images/<?php echo $Appartement->url1 ?>.jpg  alt='plouf'/><?php ;}?></td>
</tr>
<tr>
<td><?php if (!empty($Appartement->url2)){?><img onClick="ChangeImage(this.src);" id='image2' src=<?php $_SERVER['HTTP_ORIGIN'] ?>/images/<?php echo $Appartement->url2 ?>.jpg  alt='evrzgr'/><?php ;}?></td>
</tr>
<tr>
<td><?php if (!empty($Appartement->url3)){?><img onClick="ChangeImage(this.src);" id='image3' src=<?php $_SERVER['HTTP_ORIGIN'] ?>/images/<?php echo $Appartement->url3 ?>.jpg  alt='erg'/><?php ;}?></td>
</tr>
<tr>
<td><?php if (!empty($Appartement->url4)){?><img onClick="ChangeImage(this.src);" id='image4' src=<?php $_SERVER['HTTP_ORIGIN'] ?>/images/<?php echo $Appartement->url4 ?>.jpg  alt='erg'/><?php ;}?></td>
</table>
</div>
</div>
<?php 
$site->footer();

